/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */

typedef struct ListNode ListNode;

ListNode* deleteMiddle(ListNode* head)
{

    if (!head->next)
        return NULL;

    if (!head->next->next)
    {
        head->next = NULL;
        return head;
    }

    ListNode* slow, * fast;
    slow = fast = head;

    while (fast && fast->next)
    {
        slow = slow->next;
        if (fast->next)
            fast = fast->next->next;
    }

    slow->val = slow->next->val;
    slow->next = slow->next->next;

    return head;
}